<?php
/**
 * Created by PhpStorm.
 * User: bzing
 * Date: 2017/7/27 0027
 * Time: 下午 3:02
 */
namespace app\api\controller;
use app\models\Models;

class Recharge extends Base{
    /**
     * 充值产品列表
     * @return \think\response\Json
     */
    public function rechargeList(){
        if(request()->isPost()){
            try{
                $params = self::checkLogin(['equipment','encrypt']);
                $account = new Models('account');
                $recharge = new Models('recharge_type');
                $list['balance'] = $account->getValue(['uid'=>$params['uid']],'coin_balance');
                $list['list'] = $recharge->_select(['status'=>Models::STATUS_ON]);
            } catch (\Exception $e){
                return json(self::formatResult($e->getCode(),$e->getMessage()));
            }
            return json(self::formatSuccessResult($list));
        }
    }

    /**
     * 代币记录
     * @return \think\response\Json
     */
    public function tokenRecord(){
        if(request()->isPost()){
            try{
                $params = self::checkLogin(['equipment','encrypt']);
                $record = new Models('token_record');
                $list = $record->_page(['uid'=>$params['uid']],'coin,action,create_time','create_time desc',[],$params['page']);
                $list = $list->items();
                foreach($list as $k=>$v){
                    $t = date('Y-m-d',$v['create_time']);
                    $arr[$t][] = $v;
                }
            } catch (\Exception $e){
                return json(self::formatResult($e->getCode(),$e->getMessage()));
            }
            return json(self::formatSuccessResult($arr));
        }
    }
}